<!doctype html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/_mozilla/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
promise_test(t => {
    window.testRunner.setBluetoothMockDataSet(adapter_type.two_heart_rate);
    return window.navigator.bluetooth.requestDevice({
        filters: [{services: [generic_access.name]}]
    })
    .then(device => device.gatt.connect())
    .then(gattServer => {
        return gattServer.getPrimaryService(generic_access.name)
        .then(service => service.getCharacteristic(device_name.name))
        .then(c => {
            let characteristic = c;
            gattServer.disconnect();
            return gattServer.connect()
            .then(() => characteristic);
        });
    })
    .then(characteristic => {
        let promises = [];
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.getDescriptor(number_of_digitals.name)));
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.getDescriptors(number_of_digitals.name)));
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.getDescriptors()));
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.readValue()));
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.writeValue(new Uint8Array(1))));
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.startNotifications()));
        promises.push(promise_rejects_dom(t, 'InvalidStateError', characteristic.stopNotifications()));
        return Promise.all(promises);
    });
}, 'Calls on a characteristic after we disconnect and connect again. Should reject with InvalidStateError.');
</script>
